<template>
    <div style="display: flex;">
        <Card title="编辑场景分类明细" dis-hover icon="md-document" style="flex: 1;">
            <Form ref="addfrom" :model="FormData" :rules="FormRules" :label-width="140">
                <Row>
                    <Col span="18" offset="3">
                    <FormItem label="场景分类名称：" prop="categoryName">
                        <Input v-model="FormData.categoryName" maxlength="20" show-word-limit
                            placeholder="请输入分类名称"></Input>
                    </FormItem>
                    </Col>
                    <Col span="18" offset="3">
                    <FormItem label="位置：" prop="position">
                        <InputNumber v-model="FormData.position" :precision="0" type="number" placeholder="位置" :max="999" :min="0" />
                    </FormItem>
                    </Col>
                    <Col span="18" offset="3">
                    <FormItem label="是否启用：">
                        <RadioGroup v-model="FormData.categoryState">
                            <Radio label="1">启用</Radio>
                            <Radio label="2">禁用</Radio>
                        </RadioGroup>
                    </FormItem>
                    </Col>
                    <Col span="18" offset="3">
                    <FormItem label="备注：">
                        <Input type="textarea" :autosize="{minRows: 2,maxRows: 5}" maxlength="100" show-word-limit
                            v-model="FormData.categoryDesc" placeholder="请输入描述"></Input>
                    </FormItem>
                    </Col>
                    <Col span="18" offset="3">
                    <FormItem>
                        <Button type="primary" @click="handleSubmit('FormData')">提交</Button>
                        <Button @click="handleReset('FormData')" class="ivu-ml-8">取消</Button>
                    </FormItem>
                    </Col>
                </Row>
            </Form>
        </Card>
    </div>
</template>
<script>
    import {
        mapState,
        mapMutations
    } from 'vuex';
    import util from '@/libs/util';
    import { ApiRequest } from '@api/basePage';
    import {
        myTreeDataUtils,
    } from '@/assets/js/commonUtils';

    export default {
        components: {
        },
        data() {
            return {
                multipledata: false,
                isRootCategory: false,
                showRight: false,
                showCategory: true,
                util: util,
                dynamicData: {},
                pagePath: '', // 当前路由
                FormRules: {
                    categoryName: [{ required: true, message: '请填写分类名称', trigger: 'blur' },
                    { type: 'string', min: 1, message: '分类名称不得少于一个字符', trigger: 'blur' },],
                    categoryNo: [{ required: true, message: '请填写分类编码', trigger: 'blur' },
                    { type: 'string', min: 1, message: '分类编码不得少于一个字符', trigger: 'blur' },],
					position: [{ required: true, message: '请填写位置' }],
                    categoryDesc: [{ required: true, message: '请填写描述', trigger: 'blur' },
                    { type: 'string', min: 1, message: '描述不得少于一个字符', trigger: 'blur' },],
                },
                FormData: {
                    categoryName: '',
                    categoryDesc: '',
                    levelNum: '',
                    position: 0,
                    categoryState: '1',
                    uuid: '',
                    parentUuid: '',
                    version: ''
                },
                rootDate: [],
                uuid: '',
            }
        },
        watch: {
            '$route': function () {
                this.$nextTick(() => {
                    this.$router.go(0);
                })
            }
        },
        created() {
            this.getConfigData();
            this.initData();
        },
        mounted() { },
        methods: {
            // 获取初始配置信息
            getConfigData() {
                this.pagePath = this.$route.path;
                let dynamicData = require('./configjs/sceneModelManageAdd').default;
                this.requestApi = dynamicData.requestApi; // 页面所需接口集合
                this.$set(this.$data, 'dynamicData', dynamicData);
                this.uuid = this.$route.query.uuid;
            },
            // 初始化数的数据
            initData() {
                let data = {
                    'uuid': this.uuid,
                }
                // 初始化
                ApiRequest(this.requestApi.baseGetByUuid.url,
                    this.requestApi.baseGetByUuid.type, data, true).then(res => {
                        if (res.retStatus === '1') {
                            this.FormData.categoryName = res.retData.categoryName;
                            this.FormData.categoryNo = res.retData.categoryNo;
                            this.FormData.categoryDesc = res.retData.categoryDesc;
                            this.FormData.position = res.retData.position;
                            this.FormData.categoryState = res.retData.categoryState;
                            this.FormData.levelNum = res.retData.levelNum;
                            this.FormData.parentUuid = res.retData.parentUuid;
                            this.FormData.uuid = res.retData.uuid;
                            this.FormData.version = res.retData.version;
                        }
                    })
            },
            handleSubmit(FormData) {
                if (this.FormData.categoryName === '') {
                    this.$Message.error('请填写分类名称');
                    return;
                }
                if (this.FormData.position === '') {
                    this.$Message.error('位置信息不能为空');
                    return;
                }
                if (this.FormData.categoryState === '') {
                    this.$Message.error('请选择是否启用');
                    return;
                }
                let data = {
                    'parentUuid': this.FormData.parentUuid,
                    'categoryName': this.FormData.categoryName,
                    'categoryDesc': this.FormData.categoryDesc,
                    'position': this.FormData.position,
                    'categoryState': this.FormData.categoryState,
                    'uuid': this.FormData.uuid,
                    'version': this.FormData.version,
                    'levelNum': this.FormData.levelNum,
                }
                // 创建分类
                ApiRequest(this.requestApi.updatePlatCategory.url,
                    this.requestApi.updatePlatCategory.type, data, false).then(res => {
                        if (res.retStatus === '1') {
                            //this.initData();
                            this.$Message.success('提交成功');
                            this.$router.go(-1);
                        }
                    })
            },
            clearData() {
                this.FormData.uuid = '';
                this.FormData.categoryName = '';
                this.FormData.categoryDesc = '';
                this.FormData.categoryNo = '';
                this.FormData.position = '';
            },
            handleReset() {
                this.$router.go(-1);
            },
            treeSelectChange(arr, item) {
                this.FormData.uuid = item.uuid;
                if (item.levelNum === "3") {
                    this.multipledata = true;
                    this.showRight = true;
                    this.showCategory = true;
                } else if (item.levelNum === "4") {
                    this.showRight = false;
                    this.showCategory = false;
                } else {
                    this.multipledata = false;
                    this.showRight = true;
                    this.showCategory = true;
                }
            },
        }
    }
</script>
<style lang="less" scoped>
    .qw-kuang {}
</style>